package com.rebecca.demo_01.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2

public class SwaggerConfig {

    @Bean
    public Docket createRestAPi(){
        //构建文档
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        //文档信息
        Docket build = docket.apiInfo(apiInfo())
                //查询
                .select()
                //注解包的路径
                .apis(RequestHandlerSelectors.basePackage("com.rebecca.demo_01.controller"))
                //任何路径
                .paths(PathSelectors.any())
                .build();
        return build;

    }


    private ApiInfo apiInfo(){
        //文档对象构造器
        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
        //文档标题
        ApiInfo apiInfo = apiInfoBuilder.title("SpringBoot 项目学习API 文档")
                .description("springboot 项目集成Swagger2 实例") //描述信息
                .version("v1.0") // 版本号
                .contact(new Contact("ximing","https://gitee.com/ximing001","1505020971@qq.com")) //联系人
                .license("声明许可") //声明许可
                .licenseUrl("https://gitee.com/ximing001") //许可路径
                .build();
        return apiInfo;
    }


}
